﻿using System;
using System.Collections.Generic;
using System.Transactions;
using Bingosoft.Data;
using HHMMS.WorkFlow.Model;

namespace HHMMS.WorkFlow.Service
{
	/// <summary>
	///表示对表WorkflowDefinition的所有操作的实现。
	/// </summary>
    public class WorkflowDefinitionService
    {
        private readonly Dao dao = Dao.Get();

        private WorkflowDefinitionService()
        { }

        private static WorkflowDefinitionService instance = null;
        /// <summary>
        /// WorkflowDefinition服务类的单例。
        /// </summary>
        public static WorkflowDefinitionService Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (typeof(WorkflowDefinitionService))
                    {
                        instance = new WorkflowDefinitionService();
                    }
                }
                return instance;
            }
        }

        public void Delete(int workflowId)
        {
            this.dao.ExecuteNonQuery("workflow.workflowdefinition.delete", new
            {
                WorkflowId = workflowId
            });
        }

        public void Insert(WorkflowDefinition workflowDefinition)
        {
            this.dao.ExecuteNonQuery("workflow.workflowdefinition.insert", workflowDefinition);
        }

        public void Update(WorkflowDefinition workflowDefinition)
        {
            this.dao.ExecuteNonQuery("workflow.workflowdefinition.update", workflowDefinition);
        }

        public WorkflowDefinition Single(int workflowId)
        {
            return this.dao.QueryEntity<WorkflowDefinition>("workflow.workflowdefinition.single", new
            {
                WorkflowId = workflowId
            });
        }
    }
}